﻿//用于列表页和详细页公用的权限部分
var customerRight = {};
var cr = customerRight;
//判断角色权限
customerRight.CheckRightRol = function (el, key, isAlert) {
    var roleRight = $("#hidPermissions").val();
    var myDepartments = $("#hidMyDepartments").val();
    var operator = $("#hidOperatorID").val();
    var item = $(el);
    if (roleRight.indexOf(key + "-MySelf") > -1) {
        if (item.attr("userid") != operator) {
            if (isAlert) {
                $.OKDialogAgency('<div class="tc">您拥有的是本人权限,但该记录不属于你本人！</div>');
            }
            return false;
        }
    }
    else if (roleRight.indexOf(key + "-MyDepartment") > -1) {
        if (myDepartments.indexOf(item.attr("departmentid")) == -1) {
            if (isAlert) {
                $.OKDialogAgency('<div class="tc">您拥有的是本部权限,但该记录不属于你的部门！</div>');
            }
            return false;
        }
    }
    else if (roleRight.indexOf(key + "-All") > -1) {
        return true;
    }
    else {
        if (isAlert) {
            $.OKDialogAgency('<div class="tc">您没有对应的操作权限！</div>');
        }
        return false;
    }
    return true;
}
customerRight.CheckRightRols = function (els, key, isAlert) {
    var roleRight = $("#hidPermissions").val();
    var myDepartments = $("#hidMyDepartments").val();
    var operator = $("#hidOperatorID").val();
    for (var i = 0; i < els.length; i++) {
        var item = $(els[i]);
        if (roleRight.indexOf(key + "-MySelf") > -1) {
            if (item.attr("userid") != operator) {
                if (isAlert) {
                    $.OKDialogAgency('<div class="tc">您拥有的是本人权限,但该记录不属于你本人！</div>');
                }
                return false;
            }
        }
        else if (roleRight.indexOf(key + "-MyDepartment") > -1) {
            if (myDepartments.indexOf(item.attr("departmentid")) == -1) {
                if (isAlert) {
                    $.OKDialogAgency('<div class="tc">您拥有的是本部权限,但该记录不属于你的部门！</div>');
                }
                return false;
            }
        }
        else if (roleRight.indexOf(key + "-All") > -1) {
            return true;
        }
        else {
            if (isAlert) {
                $.OKDialogAgency('<div class="tc">您没有相应的权限！</div>');
            }
            return false;
        }
    }
    return true;
}
customerRight.CheckEditRight = function (rightKey, seletor) {
    var roleRight = $("#hidPermissions").val();
    if ((roleRight.indexOf(rightKey) == -1)) {
        seletor.hide();
    }
}
customerRight.CheckRight = function (rightKey) {
    var roleRight = $("#hidPermissions").val();
    return roleRight.indexOf(rightKey) > -1;
}
